home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue58 / DragDrop / OldDragU.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-04-10  |  1.3 KB  |  69 lines

  1. unit OldDragU;
  2.  
  3. interface
  4.  
  5. uses
  6.   WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   ExtCtrls, StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     lstFiles: TListBox;
  12.     procedure FormCreate(Sender: TObject);
  13.     procedure FormDestroy(Sender: TObject);
  14.   private
  15.     { Private declarations }
  16.   public
  17.     procedure WMDropFiles(var Msg: TWMDropFiles);
  18.       message wm_DropFiles;
  19.   end;
  20.  
  21. var
  22.   Form1: TForm1;
  23.  
  24. implementation
  25.  
  26. {$R *.DFM}
  27.  
  28. uses
  29.   ShellAPI;
  30.  
  31. procedure TForm1.FormCreate(Sender: TObject);
  32. begin
  33.   DragAcceptFiles(Handle, True);
  34. end;
  35.  
  36. procedure TForm1.FormDestroy(Sender: TObject);
  37. begin
  38.   DragAcceptFiles(Handle, False);
  39. end;
  40.  
  41. procedure TForm1.WMDropFiles(var Msg: TWMDropFiles);
  42. {$ifdef Windows}
  43. const
  44.   MAX_PATH=255;
  45. {$endif}
  46. var
  47.   Pt: TPoint;
  48.   Count, Loop: Integer;
  49.   Buf: array[0..MAX_PATH] of Char;
  50. begin
  51.   try
  52.     Msg.Result := 0;
  53.     DragQueryPoint(Msg.Drop, Pt);
  54.     Caption := Format('Files dropped at (%d,%d)',
  55.       [Pt.X, Pt.Y]);
  56.     Count := DragQueryFile(
  57.       Msg.Drop, Cardinal(-1), Buf, SizeOf(Buf));
  58.     for Loop := 0 to Pred(Count) do
  59.     begin
  60.       DragQueryFile(Msg.Drop, Loop, Buf, SizeOf(Buf));
  61.       lstFiles.Items.Add(StrPas(Buf))
  62.     end
  63.   finally
  64.     DragFinish(Msg.Drop)
  65.   end
  66. end;
  67.  
  68. end.
  69.